<template>
  <div>
    <!--  维修工单选择 -->
    <TopFilter :list="topFilterInit" :cols="3" :collapse="collapse" labelWidth="90" @filterChange="changeHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      height="auto"
      selectionType="single"
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :fetchapi="fetchapi"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      :isPagination="true"
    >
    </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <multiuse-button type="primary" :click="saveDialog.bind()" :disabled="disableds">添 加</multiuse-button>
      <multiuse-button @click="closeDialog">关 闭</multiuse-button>
    </div>
  </div>
</template>
<script>
import { queryRepairVehicleList } from '@/api/repair/common';
import { dictionary } from '@/utils/dictMixin';
export default {
  mixins: [dictionary],
  data() {
    return {
      disableds: true,
      visible: false,
      visibleDrawer: false,
      collapse: true,
      infoId: null,
      topFilterInit: this.topFilterInitFun(),
      flterValue: {}, //参数
      columns: this.creatHeader(),
      fetchapi: queryRepairVehicleList,
      fetchParams: {}, //ipa 接口
      selectedRows: [] //选中经销商
    };
  },
  created() {
  },
  methods: {
    //搜索数据
    topFilterInitFun() {
      return [
        { type: 'INPUT', label: '车牌', fieldName: 'license', placeholder: '请输入车牌...', initialValue: '' },
        { type: 'INPUT', label: 'VIN', fieldName: 'vin', placeholder: '请输入VIN...', initialValue: '' },
        // { type: 'INPUT', label: '车主姓名', fieldName: 'ownerName', placeholder: '请输入车主姓名...', initialValue: '' },
        // { type: 'INPUT', label: '车主电话', fieldName: 'mobile', placeholder: '请输入车主电话...', initialValue: '' }
      ];
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
      console.log(val);
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        { title: 'VIN', dataIndex: 'VIN', sorter: true, width: 150 },
        { title: '车牌号', dataIndex: 'LICENSE', sorter: true },
        { title: '发动机号', dataIndex: 'ENGINE_NO', sorter: true },
        { title: '品牌', dataIndex: 'BRAND_NAME', sorter: true },
        { title: '车系', dataIndex: 'SERIES_NAME', sorter: true },
        { title: '车型', dataIndex: 'MODEL_NAME', sorter: true },
        // { title: '销售日期', dataIndex: 'SALES_DATE', sorter: true , dateFormat: 'yyyy-MM-dd'},
        // { title: '保修起始日期', dataIndex: 'WRT_BEGIN_DATE', sorter: true , dateFormat: 'yyyy-MM-dd'},
        // { title: '保修结束日期', dataIndex: 'WRT_END_DATE', sorter: true, dateFormat: 'yyyy-MM-dd' },
        // { title: '发动机号', dataIndex: 'ENGINE_NO', sorter: true },
        // { title: '车主姓名', dataIndex: 'OWNER_NAME', sorter: true },
        // { title: '车主手机号', dataIndex: 'MOBILE', sorter: true },
        // { title: '车辆用途', dataIndex: 'VEHICLE_PURPOSE', sorter: true, render: props => {    //编码转汉字
        //     return <span>{this.createDictText(props.row.VEHICLE_PURPOSE, '1511')}</span>;
        //   } },
        // { title: '用户属性', dataIndex: 'BUSINESS_KIND', sorter: true , render: props => {    //编码转汉字
        //     return <span>{this.createDictText(props.row.BUSINESS_KIND, '4103')}</span>;
        //   } },
        // { title: '行驶里程', dataIndex: 'MILEAGE', sorter: true },
        // { title: '送修人姓名', dataIndex: 'DELIVERER', sorter: true },
        // { title: '送修人手机号', dataIndex: 'DELIVERER_MOBILE', sorter: true }
      ];
    },
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      this.disableds = this.selectedRows.length <= 0;
      console.log(this.selectedRows);
    },
    //保存
    saveDialog() {
      this.selectedRows.map(x=>{
        x.VEHICLE_PURPOSE=this.createDictText(x.VEHICLE_PURPOSE, '1511');
        // x.BUSINESS_KIND=this.createDictText(x.BUSINESS_KIND, '4103');
      })
      this.$emit('save', this.selectedRows);
    },
    //取消操作
    closeDialog() {
      this.$emit('close', { visible: false, data: this.selectedRows, type: 'close' });
    },
    chooseOrderNo() {
      this.visible = true;
    }
  }
  // mounted() {
  //   this.BaseTable = this.$refs.listModal.$refs.pageTable;
  // }
};
</script>

<style lang="less" scoped></style>
